package com.exam.service.impl;

import com.exam.mapper.ScoreMapper;
import com.exam.pojo.Score;
import com.exam.service.ScoreService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScoreServiceImpl implements ScoreService {
    @Resource
    private ScoreMapper scoreMapper;

    @Override
    public PageInfo<Score> queryByStudentIdPage(Integer studentId, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Score> scores = scoreMapper.queryByStudentId(studentId);
        PageInfo<Score> pageInfo = new PageInfo<>(scores);
        return pageInfo;
    }

    @Override
    public boolean isScore(Integer studentId, Integer examId) {
        List<Score> scores = scoreMapper.queryByStudentIdAndExamId(studentId, examId);
        if (scores.size()==0){
            return false;
        }
        return true;
    }

    @Override
    public int add(Score score) {
        return scoreMapper.insert(score);
    }

    @Override
    public List<Score> queryByStudentId(Integer studentId) {
        return scoreMapper.queryByStudentId(studentId);
    }

    @Override
    public List<Score> queryByExamId(Integer examId) {
        return scoreMapper.queryByExamId(examId);
    }
}
